package xworker.gluon.glisten.control;

import com.gluonhq.charm.glisten.control.Snackbar;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.util.JavaFXUtils;

public class SnackbarActions {
    static{
        PropertyFactory.regist(Snackbar.class, "onActionProperty", o -> {
            Snackbar obj = (Snackbar) o;
            return obj.onActionProperty();
        });
        PropertyFactory.regist(Snackbar.class, "actionTextProperty", o -> {
            Snackbar obj = (Snackbar) o;
            return obj.actionTextProperty();
        });
    }

    public static void init(Snackbar node, Thing thing, ActionContext actionContext) {
        String actionText = JavaFXUtils.getObject(thing, "actionText", actionContext);
        if (actionText != null) {
            node.setActionText(actionText);
        }

    }

    public static Snackbar create(ActionContext actionContext) {
        Thing self = actionContext.getObject("self");

        String message = JavaFXUtils.getObject(self, "message", actionContext);
        Snackbar node = new Snackbar(message);
        init(node, self, actionContext);

        actionContext.peek().put("parent", node);
        for (Thing child : self.getChilds()) {
            child.doAction("create", actionContext);
        }

        actionContext.g().put(self.getMetadata().getName(), node);
        return node;
    }

}